package com.example.mychat.admiservice.controller;


import com.example.userservice.service.UserInfoService;
import org.example.annotation.GlobalInteceptor;
import org.example.controller.ABaseController;
import org.example.entity.po.UserInfo;
import org.example.entity.query.UserInfoQuery;
import org.example.entity.vo.PaginationResultVO;
import org.example.entity.vo.ResponseVO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * @Description
 * @Author susu
 * @Date 2024/9/8
 */
@RestController
@RequestMapping("/admin")
public class AdminController extends ABaseController {

    @Resource
    private UserInfoService userInfoService;

    @RequestMapping("/loadUser")
    @GlobalInteceptor(checkAdmin = true)
    public ResponseVO loadUser(UserInfoQuery query){
        query.setOrderBy("create_time desc");
        PaginationResultVO<UserInfo> listByPage = userInfoService.findListByPage(query);
        return getSuccessResponseVO(listByPage);
    }

    @RequestMapping("/updateUserStatus")
    @GlobalInteceptor(checkAdmin = true)
    public ResponseVO updateUserStatus(@NotNull Integer status,@NotEmpty String userId){
        userInfoService.updateUserStatus(status,userId);

        return getSuccessResponseVO(null);
    }

    @RequestMapping("/forceOffLine")
    @GlobalInteceptor(checkAdmin = true)
    public ResponseVO forceOffLine(@NotEmpty String userId){
        userInfoService.forceOffLine(userId);

        return getSuccessResponseVO(null);
    }
}
